<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>上传表关系</title>
	<link rel="stylesheet" type="text/css" href="./static/css/easyui.css">
	<link rel="stylesheet" type="text/css" href="./static/css/icon.css">
	<link rel="stylesheet" type="text/css" href="./static/css/demo.css">
	<script type="text/javascript" src="./static/js/jquery.min.js"></script>
	<script type="text/javascript" src="./static/js/jquery.easyui.min.js"></script>
</head>
<body>
	<h2>表对应关系</h2>
	<div style="margin:20px 0;"></div>
	<div class="easyui-panel" title="表对应关系" style="width:600px">
		<div style="padding:10px 60px 20px 60px">
			<form id="tableRelationForm" method="post" enctype="multipart/form-data">
			    <div>
					<label for="relation" style="width:100px;">表关系:</label>
					<input class="easyui-validatebox" type="file" name="relation" data-options="required:true" />
			    </div>		
			</form>
			<div style="text-align:center;padding:5px">
		    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
		    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
		    </div>
	    </div>	
    </div>	
	<script type="text/javascript">

		function submitForm(){
			$.messager.progress();	// display the progress bar
			$('#tableRelationForm').form('submit', {
				url: getRootPath()+'/tableRelationUpload',
				onSubmit: function(){
					var isValid = $(this).form('enableValidation').form('validate');
					if (!isValid){
						$.messager.progress('close');	// hide progress bar while the form is invalid
					}
					return isValid;	// return false will stop the form submission
				},
				success: function(responseStr){
					var response = JSON.parse(responseStr);
					$.messager.progress('close');	// hide progress bar while submit successfully
					$.messager.show({
						title:'操作结果',
						msg:(response&&response.success)?"操作成功":("操作失败:"+response.error)
					});
				}
			});			
		}
		function clearForm(){
			$('#tableRelationForm').form('clear');
		}

		//js获取项目根路径，如： http://localhost:8083/uimcardprj
		function getRootPath(){
		    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
		    var curWwwPath=window.document.location.href;
		    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
		    var pathName=window.document.location.pathname;
		    var pos=curWwwPath.indexOf(pathName);
		    //获取主机地址，如： http://localhost:8083
		    var localhostPaht=curWwwPath.substring(0,pos);
		    //获取带"/"的项目名，如：/uimcardprj
		    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
		    return(localhostPaht+projectName);
		}
	</script>
</body>
</html>